/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 7/06/2009, 02:52:25 AM
 */

package presentacion;

import java.awt.SystemTray;
import negocio.control.AdministradoraListaNoreceptores;
import negocio.control.ProgramadoraDeEnvios;

/**
 *
 * @author Administrador
 */
public class Principal extends javax.swing.JFrame {
    
    /** Creates new form Principal */
    public Principal() {
        try
        {
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception ex)
        {
            //Dejar el look and feel de java
        }
        AdministradoraListaNoreceptores.getInstancia();
        ProgramadoraDeEnvios.getInstancia();
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        servidoresEnvio = new javax.swing.JButton();
        listas = new javax.swing.JButton();
        enviarCorreo = new javax.swing.JButton();
        salir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SECM");

        jLabel1.setFont(new java.awt.Font("Georgia", 3, 24));
        jLabel1.setText("SECM");

        jLabel2.setText("Sistema de Envío de Correos Masivos");

        servidoresEnvio.setText("Configurar Servidores de Envío");
        servidoresEnvio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                servidoresEnvioActionPerformed(evt);
            }
        });

        listas.setText("Configurar Listas de Correo");
        listas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listasActionPerformed(evt);
            }
        });

        enviarCorreo.setText("Programar/Enviar Correo");
        enviarCorreo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enviarCorreoActionPerformed(evt);
            }
        });

        salir.setText("Salir");
        salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(jLabel1))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(servidoresEnvio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addComponent(listas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(enviarCorreo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(salir, javax.swing.GroupLayout.Alignment.TRAILING)))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(33, 33, 33)
                .addComponent(servidoresEnvio)
                .addGap(18, 18, 18)
                .addComponent(listas, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(enviarCorreo)
                .addGap(31, 31, 31)
                .addComponent(salir)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void servidoresEnvioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_servidoresEnvioActionPerformed
        if (servidor != null) {
            if (!servidor.isDisplayable()) {
                servidor = new IGConfiguracionServidorSMTP();
                servidor.setVisible(true);
                servidor.toFront();
            } else {
                servidor.toFront();
            }
        }else{
            servidor = new IGConfiguracionServidorSMTP();
            servidor.setVisible(true);
            servidor.toFront();
        }
}//GEN-LAST:event_servidoresEnvioActionPerformed

    private void listasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listasActionPerformed
        if (lista!=null) {
            if (!lista.isDisplayable()) {
                lista = new IGListaDeCorreos();
                lista.setVisible(true);
                lista.toFront();
            } else {
                lista.toFront();
            }
        } else {
            lista = new IGListaDeCorreos();
            lista.setVisible(true);
            lista.toFront();
        }
}//GEN-LAST:event_listasActionPerformed

    private void enviarCorreoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enviarCorreoActionPerformed
        if (correo!=null) {
            if (!correo.isDisplayable()) {
                correo = new IGEnvioDeCorreo();
                correo.setVisible(true);
                correo.toFront();
            } else {
                correo.toFront();
            }
        } else {
            correo = new IGEnvioDeCorreo();
            correo.setVisible(true);
            correo.toFront();
        }
}//GEN-LAST:event_enviarCorreoActionPerformed

    private void salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirActionPerformed
        this.dispose();
        System.exit(0);
}//GEN-LAST:event_salirActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }

    //Variables de la clase
    private IGConfiguracionServidorSMTP servidor;
    private IGEnvioDeCorreo correo;
    private IGListaDeCorreos lista;

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton enviarCorreo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JButton listas;
    private javax.swing.JButton salir;
    private javax.swing.JButton servidoresEnvio;
    // End of variables declaration//GEN-END:variables

}
